<?php
	header("Content-type:text/x-json; charset=UTF-8"); 
	header("Cache-Control: no-store, no-cache, must-revalidate"); 
	header("Cache-Control: post-check=0, pre-check=0", false); 

	$objConnect = oci_connect("hospital", "hospital", "//localhost/XE"); 

	$page = $_POST['page']; 
	$rp = $_POST['rp']; 
	$sortname = $_POST['sortname']; 
	$sortorder = $_POST['sortorder']; 

	if (!$sortname) $sortname = 'STF_ID'; 
	if (!$sortorder) $sortorder = 'ASC'; 
	if (!$page) $page = 1; 
	if (!$rp) $rp = 10; 

	$start = (($page-1) * $rp);
	$limit = "LIMIT $start, $rp";
	$sort = "ORDER BY $sortname $sortorder";

	$strSQL = "SELECT * FROM STAFF WHERE JOB_TYPE LIKE 'NUR' $sort";
	$objParse = oci_parse($objConnect, $strSQL);
	oci_execute ($objParse,OCI_DEFAULT);

	$total = oci_fetch_all($objParse, $Result);

	$q = "SELECT * FROM STAFF WHERE 1 $sort $limit";
	$objParse = oci_parse($objConnect, $strSQL);
	oci_execute ($objParse,OCI_DEFAULT);

	$data['page'] = intval($page); // 
	$data['total'] = intval($total); //
	while ($row = oci_fetch_array($objParse,OCI_BOTH)) {
		$rows[] = array(
		"id" => $row['STF_ID'],
		"cell" => array(
			$row['STF_ID']
			,$row['F_NAME']
			,$row['L_NAME']
			,$row['JOB_TYPE']
			,$row['SALARY']
			,$row['START_CONTACT']
			,$row['END_CONTACT']
			)
		);	
	}
	$data['rows'] = $rows;
	echo json_encode($data);
	exit;

?>
